//////////////////////////////////////////////////////////////////////////////////
//	File Name:	BitmapFontPrinter.cpp
//	Author	 :	Yuri Oyoko
//	Purpose	 :	Used for printing out bitmap fonts
//////////////////////////////////////////////////////////////////////////////////

#include "BitmapFontPrinter.h"
#include "Definitions.h"
#include <string.h>
#include "SGD Wrappers/CSGD_TextureManager.h"

BitmapFontPrinter::BitmapFontPrinter()
{
	ImageID = CSGD_TextureManager::GetInstance()->LoadTexture(TextBitmap, D3DCOLOR_XRGB(0,0,0));
}
BitmapFontPrinter::~BitmapFontPrinter()
{
}
void BitmapFontPrinter::Print(char* TextToPrint, int XPos, int YPos, float Scale, DWORD TextColor)
{
	int Length = (int)strlen(TextToPrint);
	int Rows = 0;
	for(int i = 0; i < Length; i++)
	{
		char CurrentCharacter = TextToPrint[i];
		if(CurrentCharacter == ' ')
			continue;

		CurrentCharacter = toupper(CurrentCharacter);
		StartCharacter = 32;
		int ID = CurrentCharacter - StartCharacter;
		RECT LetterRect = CellAlgorithm(ID);
		
		CSGD_TextureManager::GetInstance()->Draw(ImageID, XPos + (i*CellWidth*Scale), YPos, Scale, Scale, &LetterRect, 0.0f, 0.0f, 0.0f, TextColor);

	}
}

RECT BitmapFontPrinter::CellAlgorithm(int CellID)
{
	RECT LetterRect;
	CellWidth = 32;
	CellHeight = 32;
	NumberOfColumns = 16;
	
	LetterRect.left = CellWidth * (CellID % NumberOfColumns);
	LetterRect.top = CellHeight * (CellID / NumberOfColumns);
	LetterRect.bottom = LetterRect.top + CellHeight;
	LetterRect.right = LetterRect.left + CellWidth;
	return LetterRect;
}